/*
 * event.h
 *
 *  Created on: May 21, 2012
 *      Author: root
 */
#include "unp.h"
#include "readBuffer.h"

typedef enum {
	U_CMD, //0
	S_REPLY, //1
	S_REPLY1, //2
	S_REPLY2, //3
	S_REPLY3, //4
	P_REPLY, //5
	DATA, //6
	I_REPLY //7

} STATE;

STATE state;


ReadBuffer *rbuf;

int connect_bit ;
int log_bit ;
int toggle ;
int passive_bit ;
int type_bit ;
int file_sockfd;


char my_addr[30];
char first_ip[40];
char ftp_serv_ip[20];
char active_data_port[10];
char res_num[10];
char response[MAXLINE];
char request[MAXLINE];
char PORT_arg[100];

int listenfd;
socklen_t addrlen, len;
struct sockaddr * cliaddr;

int n;


typedef struct {
	int cmd_num;
	int sockfd;
	char cmd[100];
	char arg1[100];
	char arg2[100];
} USER_CMD;




USER_CMD event_open(USER_CMD cmd_info);
USER_CMD event_get_put(USER_CMD cmd_info);
void event_lcd(USER_CMD cmd_info);
void event_passive();
void event_debug();
void event_type();
void event_cd(USER_CMD cmd_info);
void event_user(USER_CMD cmd_info);
int event_ls_dir_nlist(USER_CMD cmd_info);


USER_CMD state_P_REPLY(USER_CMD cmd_info);
void state_I_REPLY(USER_CMD cmd_info);
void state_S_REPLY(USER_CMD cmd_info);
int state_S_REPLY1(USER_CMD cmd_info);
USER_CMD state_S_REPLY2(USER_CMD cmd_info);
void state_S_REPLY3(USER_CMD cmd_info);
USER_CMD state_DATA(USER_CMD cmd_info);



int not_connect(USER_CMD cmd_info);
void get_myaddress(int sockfd);
void make_PORT_arg();
char parse_LF(char *cmd);
void print_response();
void send_request(int sockfd, char *cmd, char *arg1);
